package SortAll;

import java.util.Arrays;
import java.util.Random;

public class ShellSort {
    public static void main(String[] args) {
        Random random=new Random();
        int[] ints = random.ints(1,20)
                .limit(7)
                .toArray();
        test1(ints);
        System.out.println(Arrays.toString(ints));
    }
    public static void test(int[] arr){
     for (int gap=arr.length/2;gap>0;gap/=2){
         for (int i = gap; i <arr.length ; i++) {
             int j=i;
             int temp=arr[j];
             if(arr[j]<arr[j-gap]){
                 for (; j-gap >=0&&arr[j-gap]>temp ; j=j-gap) {
                     arr[j]=arr[j-gap];
                 }
                 arr[j]=temp;
             }
         }

      }
    }
    public  static  void test1(int[] num){
        for (int gap=num.length;gap>0;gap/=2){
            for (int i = gap; i < num.length; i++) {
                int j=i;
                int temp=num[j];
                if(num[j]<num[j-gap]){
                    for (; j-gap>=0 &&num[j-gap]>temp ; j-=gap) {
                        num[j]=num[j-gap];
                    }
                    num[j]=temp;
                }
            }
        }
    }
    public static void test2(int[] num) {
        for (int gap=num.length/2;gap>0;gap/=2) {
            for (int i = gap; i <num.length ; i++) {
                int j=i;
                int temp=num[j];
                for (; j-gap>=0&&num[j-gap]>temp ; j-=gap) {
                    num[j]=num[j-gap];
                }
                num[j]=temp;
            }
        }
    }
    public static  void test3(int[] ints){
        for (int gap= ints.length/2; gap>0 ; gap/=2) {
            for (int i = gap; i < ints.length ; i++) {
                int j=i; int temp=ints[j];
                if(ints[j]<ints[j-gap]){
                    for (; j-gap >=0&&ints[j]>temp ; j-=gap) {
                        ints[j]=ints[j-gap];
                    }
                    ints[j]=temp;
                }
            }
        }
    }

}
